package com.cms.bs.config;

import com.cms.bs.util.Log4jUtil;
import org.springframework.util.StringUtils;

import java.io.InputStreamReader;
import java.util.Properties;

/**
 * Created by jiang on 2016-11-15.
 */
public class Config {
    private static Properties props = new Properties();

    static {
        try {
            props.load(new InputStreamReader(Config.class.getClassLoader().getResourceAsStream("env.properties"), "UTF-8"));
        } catch (Exception e) {
            Log4jUtil.error(Config.class.getName(), "参数初始化失败: evn.properties");
            System.exit(0);
        }
    }

    public static String getPropStr(String key){
        return props.getProperty(key);
    }

    public static Object getPropObj(String key){
        return props.get(key);
    }

    /**
     *
     * @Title: getPropStrs
     * @Description: TODO 获取多个 键值， 以splitStr间隔
     * @param splitStr
     * @param keys
     * @return
     * @author: jiang
     * @date:   2016年7月4日
     */
    public static String getPropStrs(String splitStr, String... keys){
        StringBuffer sb = new StringBuffer("");
        for(String key : keys){
            if(sb.length()>0 && !StringUtils.isEmpty(splitStr)){
                sb.append(splitStr);
            }
            sb.append(Config.getPropStr(key));
        }
        return sb.toString();
    }
}
